HummDataMeansExtractor4th Dimension (~Pascal) Code for extracting logs of arithmetic means of morphological features, among specimens  // ----------------------------------------------------  // User name: Robert K. Colwell  // Date and time: 08/27/15, 16:50:15  // Modified by: Robert K. Colwell (12/7/22)  // ----------------------------------------------------  // Method: HummDataMeansExtractor  // Description:  Runs the code using three consecutive procedures  // ----------------------------------------------------LoadDataTable GetSpeciesMeans ExportSpeciesMeans   // ----------------------------------------------------  // User name (OS): Robert K. Colwell  // Date and time: 08/27/15, 15:54:17  //  // ----------------------------------------------------  // REVISED: User name (OS): Robert K. Colwell  // Date and time: 12/04/22, 15:01:59  // ----------------------------------------------------  // Method: LoadDataTable  // Description:  Reads the data table into arrays  // ----------------------------------------------------C_TEXT(Line)// CLOSE DOCUMENT(�DocNo)�� //For DebuggingDocNo:=Open document("")If (DocNo#�00:00:00�)//�DocNo:=DocNo��//*******For Debugging   Line:=ReadRecord   //Parameter recordNumberRecords:=Num(NextField )  //Number of records to readNumberColumns:=Num(NextField )  //Number of columns mophological data (NOT <>SpecimenGenusSpecies,<>SpecimenAlphaCode, or <>SpecimenSexCode)SexesToInclude:=Num(NextField )  //0 to report on all specimens, 1 for males only, 2 for females only  //Arrays of constants for specimens (text and numbers)ARRAY TEXT(<>SpecimenGenusSpecies;NumberRecords)ARRAY TEXT(<>SpeciesAlphaCode;NumberRecords)ARRAY INTEGER(<>SpeciesNumberCode;NumberRecords)ARRAY INTEGER(<>SpecimenSexCode;NumberRecords)ARRAY TEXT(<>ColumnHeaders;NumberColumns+4)  //GenusSpecies  SpeciesAlphaCode  SpeciesNumberCode  SpecimenSexCode  Elevation  Weight  Wing   //ExposedCulmen  TotalCulmen Tarsus  HalluxClaw  HalluxToe  MTC//Elevation and morphological data arrayARRAY REAL(<>SpecimenRecords;NumberRecords;NumberColumns)  //9 at presentLine:=ReadRecord   //Header recordFor ($j;1;NumberColumns+4)<>ColumnHeaders{$j}:=NextField End for   //($j;1;NumberColumns)For ($i;1;NumberRecords)  //Get the data recordsLine:=ReadRecord <>SpecimenGenusSpecies{$i}:=NextField   <>SpeciesAlphaCode{$i}:=NextField <>SpeciesNumberCode{$i}:=Num(NextField) <>SpecimenSexCode{$i}:=Num(NextField )For ($j;1;NumberColumns)<>SpecimenRecords{$i}{$j}:=Num(NextField )  //Elevation and morphological dataEnd for   //($j;1;NumberColumns) End for   //   ($i;1;NumberRecords) Else Alert("Error reading the data file")  End if   //($Test="Error")   CLOSE DOCUMENT(DocNo)  // ----------------------------------------------------  // User name (OS): Robert K. Colwell  // Date and time: 08/27/15, 16:51:40  //  // ----------------------------------------------------  // REVISED: User name (OS): Robert K. Colwell  // Date and time: 12/04/22, 15:01:59// ----------------------------------------------------  // Method: GetSpeciesMeans  // Description: Computes means among specimens of elevation and morphology data, species by species  //  // ----------------------------------------------------  //Arrays for species output (text and numbers)ARRAY TEXT(<>GenusSpeciesOut;0)ARRAY TEXT(<>SpeciesAlphaCodeOut;0)ARRAY INTEGER(<>SpeciesNumberCodeOut;0)  //Elevation and morphological output arraysARRAY REAL(<>SpeciesMeans;0;NumberColumns)  ARRAY REAL(<>SampleSizes;0;NumberColumns)ARRAY REAL(<>LogSpeciesMeans;0;NumberColumns)$PreviousSpeciesNumCode:=0  //NullMeanRecordIndex:=0  //Initialize counter for output species recsFor ($Rec;1;NumberRecords)If ((SexesToInclude=0) | (<>SpecimenSexCode{$Rec}=SexesToInclude))  //SexCode 0 to include all recs, 1 for males only, 2 for females onlyIf (<>SpeciesNumberCode{$Rec}#$PreviousSpeciesNumCode)  //New species, based on SpNumCodeMeanRecordIndex:=MeanRecordIndex+1$PreviousSpeciesNumCode:=<>SpeciesNumberCode{$Rec}  //Update  //Enlarge all output arrays by 1 elementINSERT IN ARRAY(<>GenusSpeciesOut;MeanRecordIndex)INSERT IN ARRAY(<>SpeciesAlphaCodeOut;MeanRecordIndex)INSERT IN ARRAY(<>SpeciesNumberCodeOut;MeanRecordIndex)INSERT IN ARRAY(<>SpeciesMeans;MeanRecordIndex)INSERT IN ARRAY(<>SampleSizes;MeanRecordIndex)INSERT IN ARRAY(<>LogSpeciesMeans;MeanRecordIndex)  //Fill new element<>GenusSpeciesOut{MeanRecordIndex}:=<>SpecimenGenusSpecies{$Rec}  //GenSpecies<>SpeciesAlphaCodeOut{MeanRecordIndex}:=<>SpeciesAlphaCode{$Rec}  //SpAlphaCode<>SpeciesNumberCodeOut{MeanRecordIndex}:=<>SpeciesNumberCode{$Rec}  //SpAlphaCode//<>SpecimenSexCode not output, as it varies among specimens of each speciesFor ($j;1;NumberColumns)<>SpeciesMeans{MeanRecordIndex}{$j}:=<>SpecimenRecords{$Rec}{$j}  //First specimen of a new speciesCase of : (<>SpecimenRecords{$Rec}{$j}>0)  //Data present<>SampleSizes{MeanRecordIndex}{$j}:=1: (<>SpecimenRecords{$Rec}{$j}=0)  //No data<>SampleSizes{MeanRecordIndex}{$j}:=0End case   //(($j>3)&(<>SpecimenRecords{$Rec}{$j}>0))End for   //($j;1;NumberColumns)Else   //Another specimen of the same speciesFor ($j;1;NumberColumns)  <>SpeciesMeans{MeanRecordIndex}{$j}:=<>SpeciesMeans{MeanRecordIndex}{$j}+<>SpecimenRecords{$Rec}{$j}If ((<>SpecimenRecords{$Rec}{$j}>0))  //Must skip empty recs (with zero values)<>SampleSizes{MeanRecordIndex}{$j}:=<>SampleSizes{MeanRecordIndex}{$j}+1End if   //((<>SpecimenRecords{$Rec}{$j}>0))End for   //($j;3;NumberColumns)End if   //(<>SpecimenRecords{$Rec}{1})#$PreviousSpNum) End if   //(<>SpecimenRecords{$Rec}{1}=SexCode)End for   //($Rec;1;NumberRecords)  //Compute the means and their logsFor ($i;1;MeanRecordIndex)For ($j;1;NumberColumns)  If (<>SampleSizes{$i}{$j}>0)<>SpeciesMeans{$i}{$j}:=<>SpeciesMeans{$i}{$j}/<>SampleSizes{$i}{$j}<>LogSpeciesMeans{$i}{$j}:=log(<>SpeciesMeans{$i}{$j})/log(10)   //Get log base 10End if   //(<>SampleSizes{$i}{$j}>0)End for   //($j;3;NumberColumns)End for   //($i;1;MeanRecordIndex)  // ----------------------------------------------------  // User name (OS): Robert K. Colwell  // Date and time: 08/29/15, 14:21:12  // ----------------------------------------------------  // Method: ExportSpeciesMeans  // Description  //----------------------------------------------------  // REVISED: User name (OS): Robert K. Colwell  // Date and time: 12/04/22, 15:01:59  // ----------------------------------------------------Case of : (SexesToInclude=0)$SexCodeText:="All Specimens": (SexesToInclude=1)$SexCodeText:="Male Specimens": (SexesToInclude=2)$SexCodeText:="Female Specimens"End case   //(SexCode=0)$DatasetTitle:="Hummingbird morpological data for "+$SexCodeText$DocNo:=Create document("")If ($DocNo#�00:00:00�)$Line:="Hummingbird morpological data for "+$SexCodeText+", "+String(Current date;6)+<>EndLineFor ($j;1;3)  //GenusSpecies, SpeciesAlphaCode, SpeciesNumberCode$Line:=$Line+<>ColumnHeaders{$j}+<>EndField  End for   //($j;1;3)//Skip SpecimenSexCodeFor ($j;5;NumberColumns+4)$Line:=$Line+<>ColumnHeaders{$j}+" Mean"+<>EndField+<>ColumnHeaders{$j}+" Log Mean"+<>EndField+<>ColumnHeaders{$j}+" N"+<>EndFieldEnd for   //($j;1;NumberColumns)SEND PACKET($DocNo;$Line+<>EndLine)  //Send HeadersFor ($i;1;MeanRecordIndex)$Line:=<>GenusSpeciesOut{$i}+<>EndField+<>SpeciesAlphaCodeOut{$i}+<>EndField+String(<>SpeciesNumberCodeOut{$i})+<>EndField  //GenusSpecies SpecisAlphaCode, SpeciesNumCodeFor ($j;1;NumberColumns)$Line:=$Line+String(<>SpeciesMeans{$i}{$j})+<>EndField+String(<>LogSpeciesMeans{$i}{$j})+<>EndField+String(<>SampleSizes{$i}{$j})+<>EndFieldEnd for   //($j;3;NumberColumns)SEND PACKET($DocNo;$Line+<>EndLine)  //Send data lineEnd for   //($i;1;$MeanRecordNum)CLOSE DOCUMENT($DocNo)ALERT("Results were successfully exported.")Else ALERT("Error:  The output file was not written. Try again.")End if   //�`DocNo=�